
var muststop 	= VDBFUNCS_MUST_STOP;
var showlist 	= VDBFUNCS_SHOW_LIST;
var hidelist 	= VDBFUNCS_HIDE_LIST;
var sorryg 		= VDBFUNCS_SORRY_G;
var alldevice 	= VDBFUNCS_ALL_DEVICE;
var f30t999 	= VDBFUNCS_30_999;
var connect 	= VDBFUNCS_CONNECT;
var nodata 		= VDBFUNCS_NO_DATA;
var dataerr 	= VDBFUNCS_DATA_ERR;
var stopfor 	= VDBFUNCS_STOPED;
var lostfor 	= VDBFUNCS_LOST_FOR;
var gpsfor 		= VDBFUNCS_LOST_GPS;
var unknown 	= VDBFUNCS_UNKNOW;
var devicename 	= VDBFUNCS_DEVICENAME;
var time 		= VDBFUNCS_TIME;
var ttime 		= VDBFUNCS_TTIME;
var speed 		= VDBFUNCS_STATUS;
var distance    = VDBFUNCS_DISTANCE;
var distance_review     = VDBFUNCS_DISTANCE_REVIEW;
var tdistance 	= VDBFUNCS_DISTANCE_TOTAL;
var sActive 	= VDBFUNCS_ACTIVE;
var satellite 	= VDBFUNCS_SATELLITE;
var moving 		= VDBFUNCS_MOVING;
var splay 		= VDBFUNCS_PLAY;
var sstop		= VDBFUNCS_STOP;
var driver		= VDBFUNCS_DRIVER;
var l			= VDBFUNCS_LOCATION;
var latlong		= VDBFUNCS_LAT_LONG;
var derror		= VDBFUNCS_DEV_NOT_SELECT;
//=================================================================================================
var new_loc		= VDBFUNCS_ADD_NEW;
var new_name	= VDBFUNCS_NEW_NAME;
var new_loc_type = VDBFUNCS_NEW_LOC_TYPE;
var new_loc_type_select = VDBFUNCS_SELECT_TYPE;
var new_address = VDBFUNCS_ADDRESS;
var new_contact = VDBFUNCS_CONTACT;
var new_phone = VDBFUNCS_PHONE;
var new_amount = VDBFUNCS_AMOUNT;
var new_images = VDBFUNCS_IMAGE;
var new_radius	= VDBFUNCS_RADIUS;
var units	= VDBFUNCS_UNITS;
var description	= VDBFUNCS_REMARK;
var btnsave		= VDBFUNCS_SAVE;
var btncancel		= VDBFUNCS_CANCEL;

var power_str = VDBFUNCS_POWER; // ĐậmPV: 2010-10-11 - Thêm trạng thái nguồn
var strinput1 	= VDBFUNCS_INPUT1;
var strinput2 	= VDBFUNCS_INPUT2;
var strinput3On 	= VDBFUNCS_INPUT3_ON;
var strinput3Off 	= VDBFUNCS_INPUT3_OFF;
var strinput4On 	= VDBFUNCS_INPUT4_ON;
var strinput4Off 	= VDBFUNCS_INPUT4_OFF;
var strinput_5On 	= VDBFUNCS_INPUT5_ON;
var strinput_5Off 	= VDBFUNCS_INPUT5_OFF;
// start trung add
var Vmap = null ;
var Vwaypoints ;
var Vmarker ;
var Vobjpolyline  ;
//end trung add
// =================================================================================================
function VDBFuncs()
{
    var obj=new Object();		
    obj.latitudeCurrent;		//toa do lat  tam zoom ban do hien tai
    obj.longitudeCurrent;		//toa do lon  tam zoom ban do hien tai
    obj.levelCurrent;			// cap zoom ban do
	obj.map=new Object();	    // doi tuong ban do API 
	obj.global=new Object();
	obj.loaded=false;
	//obj.map.isLoaded=function(){return falase;}				
	obj.arrIcon = new Array();
	obj.locCreating;
	var baseIcon;
    obj.ListenerDraw=null;
    obj.MarkerDraw=null;
	//=================================================================================================
	obj.InitMap = function(div)															//load map
		{
			if (VBrowserIsCompatible())
			{		   				

                document.getElementById(div).InnerHtml="";      
			    obj.map = new VMap(document.getElementById(div));
                if(Vmap ==null) Vmap = obj.map;
			    var pt = new VLatLng(16.2152328, 106.280505); 	//tao 1 diem tren map
			    obj.map.setCenter(pt, 13);						// dat diem la trung tam voi do zoom la    
			    obj.map.addControl(new VLargeMapControl(), new VControlPosition(V_ANCHOR_TOP_RIGHT, new VSize(0, 0)));
			    obj.map.addControl(new VOverviewMapControl(), new VControlPosition(V_ANCHOR_TOP_LEFT, new VSize(0, 0)));
			    obj.map.addControl(new VScaleControl(), new VControlPosition(V_ANCHOR_BOTTOM_LEFT, new VSize(0,0)));
                obj.loaded=true;    
                // start trung add
                Vmap = obj.map;
                Vwaypoints =new Array();
                obj.MarkerDraw = null;
                Vobjpolyline = new Array() ;
                
				obj.ListenerDraw=VEvent.addListener(Vmap, "click", function(overlay,point)
				 {
                   
					if(typeof(point)!="undefined")
				    {                
                         if(document.getElementById('mapType').value ==1){
                        if(document.getElementById('flagDistance').value==1){  
                             
                            var latlng = new VLatLng(point.latitude, point.longitude);                      
                            if(Vmarker==null)
                           // obj.MarkerDraw = new VMarker(latlng);    
                            Vmarker = new VMarker(latlng);                                          
                            Vwaypoints.push(point); 
                            var Vpolyline = new VPolyline(Vwaypoints, "red", 3);
                            //obj.map.addOverlay(obj.MarkerDraw);
                            //obj.map.addOverlay(Vpolyline);   
                            obj.map.addOverlay(Vmarker);
                            obj.map.addOverlay(Vpolyline);                        
                            Vobjpolyline.push(Vpolyline);                                     
                            var long = Vpolyline.getLength();
                            long = Math.round(long);
                            var unit = $('#UnitDistance').val();
                            $('#hdUnitValue').val(unit);
                            long = long/unit;
                            long=CurrentFormatted(long);
                            document.getElementById('distanceValue').value = long;                        
                        }                      
						
					}
                                    // end trung add
                     _global.locs.Infopolygon(point);                    
                 }
				 });	
				baseIcon = new VIcon(V_DEFAULT_ICON); 
				baseIcon.iconAnchor = new VPoint(100, 200);
			}		 			
		}
	//=================================================================================================
	obj.PanTo = function(nLat,nLong)
		{
			//obj.map.panTo(new VLatLng(nLat,nLong))
			obj.map.setCenter(new VLatLng(nLat,nLong),obj.GetLevel());
		}
	//=================================================================================================
	obj.GetCenter = function() 
    {
        var result = new Object();
        result.latitude  = obj.map.getCenter().latitude;
        result.longitude = obj.map.getCenter().longitude;
        return result;
    }
    obj.GetLevel = function()
    {
        return(obj.map.getLevel());
    }  
	//=================================================================================================
	obj.ZoomTo = function(nLat,nLong,nLever)
		{
			obj.map.setCenter(new VLatLng(nLat,nLong),nLever)
		}
	//=================================================================================================
	obj.Point = function(nLat,nLong)
		{
			return (new VLatLng(nLat,nLong));
		}			
	//=================================================================================================	
	obj.CreateIcon = function(newobj,nCheck,stt)  		// tao icon tren ban do
		{
			var name = newobj.name;
			var drivers1 = newobj.driver;
            var driver_phone = newobj.driverphone;
			var times = newobj.time;
			var speeds = newobj.speed;
			var distances = newobj.distance;
			var sumDistances = newobj.sumDistance;
			var positions = newobj.positions;
			var T = newobj.temperature;
			var A = newobj.intensity;
			var lats = newobj.latitude;
			var lngs = newobj.longitude;
			var statu = newobj.status;
			var gps = newobj.gps;
			var ids = newobj.id;
			var link = newobj.link;
			var input_5 = newobj.input5;
			var actives = newobj.active;
			//var stt  = newobj.stt;
			var latlng = new VLatLng(lats,lngs); 
			//alert("1");
			var tilte="";
			if(nCheck==0)
			{	
				tilte=name;
				var infowind =  '<div class="info" Style="width:230px;height:90px" align=\"left\">' + 
							devicename + name +'<br>' + 
							driver + drivers1 + ' - ' + driver_phone + '<br>' + 
							time+ ' '+ times + '<br>' + 
							speed + speeds + '<br>' + 
							distance + distances + ' Km' + '<br>' + 
							sActive + (input_5 == 1 ? strinput_5On : strinput_5Off) +', '+ actives+ "<br>"+
                            power_str + newobj.power_status + // ĐậmPV: 2010-10-11 - Thêm trạng thái nguồn
							'</div>';
			}
			if(nCheck==1)
			{
				tilte=stt;
				var infowind =  '<div class="info" Style="width:230px;height:100px" align=\"left\">' + 
							devicename + name +'<br>' + 
							driver + drivers1 + ' - ' + driver_phone + '<br>' + 
							time+' ' + times + '<br>' + 
							speed + speeds + '<br>' + 
							distance_review + distances + ' Km. ' + tdistance + sumDistances + ' Km<br>' + 
							sActive + (input_5 == 1 ? strinput_5On : strinput_5Off) +', '+ actives+"<br>"+
							'</div>';
			}				
			var icn = new VIcon();
				icn.image = link;
				icn.iconSize = new VSize(22, 22);			
				var mopt = new VMarkerOptions(icn, tilte, 
					new VTextPosition(V_ANCHOR_TOP_CENTER, new VSize(0, 10)), 
					new VTextStyle(10,'bold', '#ff0000', 'verdana'));
				var marker = new VMarker(latlng, mopt);						
			obj.map.addOverlay(marker);
			
			if(nCheck==0)
				obj.setInfoWindow(marker, infowind);
			if(nCheck==1)
				obj.SetInfoReview(marker, infowind,stt);
		    return marker;
		}
	obj.CreateIconDirection = function(newobj)  		// tao icon tren ban do
		{
			var lats = newobj.latitude;
			var lngs = newobj.longitude;
			var statu = newobj.status;
			var direction = newobj.direction;
			var latlng = new VLatLng(lats,lngs); 	
			var icn2 = new VIcon();
			icn2.image="images/tracking/"+selectAngle(direction,statu);
			icn2.iconSize = new VSize(22, 22);			
			var mopt = new VMarkerOptions(icn2);
			mopt.offset = new VSize(10, 35);
			var marker = new VMarker(latlng, mopt);						
			obj.map.addOverlay(marker);
		    return marker;
		}	
	//*****************
	obj.ShowIcon = function(icon) 
	{
		try
		{
	    if(typeof(icon)!='undefined')
	    {
	        icon.show();
	    }
		}
		catch(e)
		{	
			alert(e);	
		}
	    
	}
	//*****************
	obj.HideIcon = function(icon) 
	{
	    if(typeof(icon)!='undefined')
	    {
	        icon.hide();
	    }
	}
	//=================================================================================================	
	obj.setInfoWindow = function(marker,infoWind)
		{
			try
			{				
				VEvent.addListener(marker, "click", function(){obj.map.openInfoWindow(marker.getLatLng(), infoWind);});
			}
			catch(e)
			{
			
			}
		}
	obj.SetInfoReview=function(marker, infoWind,stt)
	{
		try
		{
			VEvent.addListener(marker, "click", function(){
																obj.map.openInfoWindow(marker.getLatLng(), infoWind);
																_global.devReview.SetHighlight(stt);
																_global.devReview.StatusR(stt);
																_global.devReview.ScrollTop(stt);
														  });
		}
		catch(e)
		{
		
		}
		
	}

    obj.UnloadMap=function()
    {
        if(obj.ListenerDraw!=null)
        {
            VEvent.removeListener(obj.ListenerDraw);
        }
    }

	//================================================================================================
	obj.RemoveOverlay=function(icon)
	{
		if(typeof(icon)!='undefined')
	    {
			obj.map.removeOverlay(icon);
		}	
	}	
	//=================================================================================================	
	obj.ShowInfo = function(newobj)				// show thong tin 
		{
			var name = newobj.name;
			var drivers1 = newobj.driver;
            var driver_phone = newobj.driverphone;
			var times = newobj.time;
			var speeds = newobj.speed;
			var distances = newobj.distance;
			var sumDistances = newobj.sumDistance;
			var positions = newobj.position;
			var lats = newobj.latitude;
			var lngs = newobj.longitude;
			var T = newobj.temperature;
			var A = newobj.intensity;
			var statu = newobj.status;
			var gps = newobj.gps;
			var ids = newobj.id;
			var input_5 = newobj.input5;
			var actives = newobj.active;
			//var link = newobj.link;
			var latlng = new VLatLng(lats,lngs); 	
			
			if(_global.checkTracking == true)
				var infowind = '<div class="info" Style="width:230px;height:90px" align=\"left\">' + 
								devicename + name +'<br>' + 
								driver + drivers1 + ' - ' + driver_phone + '<br>' + 
								time + times + '<br>' + 
								speed + speeds + '<br>' + 
								distance + distances + ' Km' + '<br>' + 
								sActive + (input_5 == 1 ? strinput_5On : strinput_5Off) +', '+ actives+"<br>"+
                                power_str + newobj.power_status + // ĐậmPV: 2010-10-11 - Thêm trạng thái nguồn
								'</div>';
			else
				var infowind = '<div class="info" Style="width:230px;height:100px" align=\"left\">' + 
								devicename + name +'<br>' + 
								driver + drivers1 + ' - ' + driver_phone + '<br>' + 
								time + times + '<br>' + 
								speed + speeds + '<br>' + 
								distance_review + distances + ' Km. ' + tdistance + sumDistances + ' Km<br>' + 
								sActive + (input_5 == 1 ? strinput_5On : strinput_5Off) +', '+ actives+"<br>"+
								'</div>';
			obj.map.openInfoWindow(latlng, infowind);
		}
	//=================================================================================================		
	obj.HideInfo = function()
		{
		    obj.map.closeInfoWindow();
			//obj.arrIcon[index].closeInfoWindow();
		}
	//=================================================================================================	
	obj.ShowLocation = function(polygon)							// addocerlay dia diem
		{		    
			polygon.show();
		}	
	//=================================================================================================	
	obj.HideLocation = function(polygon)							// addocerlay dia diem
		{
		    polygon.hide();
			//obj.map.arrIcon[index].Hide(); 
		}
	//=================================================================================================	
	obj.DeleteLocation = function(polygon)							// remove dia diem
		{
		    obj.map.removeOverlay(polygon);
			//obj.map.removeOverlay(index); 
		}
	//=================================================================================================	
	obj.DrawLocationRec = function(lat1,lon1,lat2,lon2)		// Ve hinh chu nhat
	{		
		var p1 = new VLatLng(lat1,lon1);
		var p2 = new VLatLng(lat1,lon2);
		var p3 = new VLatLng(lat2,lon2);
		var p4 = new VLatLng(lat2,lon1);
		var arrLatLngs = new Array(p1, p2, p3, p4, p1);
		var objPolygon = new VPolygon(arrLatLngs, "#ff0000",0.5,"#CCFFDF",1,0.2,{clickable:false});
		obj.map.addOverlay(objPolygon);
		return objPolygon;
	}
	//=================================================================================================	
	obj.DrawLocationRou = function(lat, lon, r)					// Ve hinh tron
		{	
			var marker = new VMarker(new VLatLng(lat, lon), new VIcon());								
			var radius = 4*r*1.609344;
			var latConv = 7347.086392356055;
			var	lngConv = 7215.3469046674845;
			var nodes = 40;
			var points = [];
			var step = parseInt(360/nodes)||10;
			for(var i=0; i<=360; i+=step)
			{
				var pint = new VLatLng(lat + (radius/latConv * Math.cos(i* Math.PI/180)), lon + (radius/lngConv * Math.sin(i *Math.PI/180)));								
				points.push(pint);
			}
			var polygon = new VPolygon(points, "#ff0000",0.5,"#CCFFDF",1,0.2,{clickable:false});
			//obj.map.addOverlay(marker);	
			obj.map.addOverlay(polygon);
			return polygon;
		}
	//=================================================================================================	
	obj.ShowFormLocation = function(lat,lon,strHTML)								// hien form nhap thong tin dia diem	
		{		
			/*var strHTML = '<div class="info" style="width:265px; height:140px;z-index:0;"><b>Tạo điểm mới:<from id ="VM"  style="margin-top:0px;" onsubmit="return frmSubmit();" onreset="map.closeInfoWindow();">'+'<table style="margin-top:0px;" ><tr><td width="55" >Tên:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>'+
										'<td><input type="text" name="txtname" size="26" id="txtname"value=""></td><br>'+
									'</tr>'+
									'<tr>'+
										'<td width="55">Ghi chú :</b> </td>'+	
										'<td><textarea name="txttemp" id="txttemp"  rows="3" cols="20"></textarea></td><br>'+										
									'</tr>'+	
									'<tr>'+
										'<td width="55"></td>'+
										'<td align="right"><input type="submit" onclick="frmSubmit()" value="Lưu" name="B1">&nbsp'+
										'<input type="reset" value="Bỏ qua" name="B2" onclick="obj.HideInfo()"></td><br>'+
									'</tr>'+
								'</table>'
								'</from></div>';*/
			obj.map.openInfoWindow(new VLatLng(lat,lon), strHTML);
		}	
	obj.ClearOverlay=function()
		{
			obj.map.clearOverlays();
		}
	obj.RemoveOnClick = function(myEventListener)
	{
		VEvent.removeListener(myEventListener);	
	}
	obj.CheckHide=function(icon)
	{
		if(icon.isHidden()==false)
			return false;
		else 
			return true;
	}
	obj.SetInfo=function(marker, infoWind)
	{
		try
		{
			VEvent.addListener(marker, "click", function(){marker.openInfoWindow(infoWind);});
		}
		catch(e)
		{
		
		}
		
	}
	obj.CreateLocal = function(latclick,lngclick)
	{
		var radius = 4*1*1.609344;
				var latConv = 7347.086392356055;
				var	lngConv = 7215.3469046674845;
				var point1 = new VLatLng(latclick + (radius/latConv * Math.cos(0* Math.PI/180)), lngclick + (radius/lngConv * Math.sin(0 *Math.PI/180)));								
				var point2 = new VLatLng(latclick + (radius/latConv * Math.cos(90* Math.PI/180)), lngclick + (radius/lngConv * Math.sin(90 *Math.PI/180)));
				var point3 = new VLatLng(latclick + (radius/latConv * Math.cos(180* Math.PI/180)), lngclick + (radius/lngConv * Math.sin(180 *Math.PI/180)));								
				var point4 = new VLatLng(latclick + (radius/latConv * Math.cos(270* Math.PI/180)), lngclick + (radius/lngConv * Math.sin(270 *Math.PI/180)));												
				
				var p1 = new VLatLng(point1.latitude,point4.longitude);
				var p2 = new VLatLng(point1.latitude,point2.longitude);
				var p3 = new VLatLng(point3.latitude,point2.longitude);
				var p4 = new VLatLng(point3.latitude,point4.longitude);
				
				obj.PanTo(latclick,lngclick);
				var arrLatLngs = new Array(p1, p2, p3, p4, p1);
				var polygon = new VPolygon(arrLatLngs, "#ff0000",0.5,"#CCFFDF",1,0.2,{clickable:false});
				obj.map.addOverlay(polygon);
	}
        
	obj.AddOnClick = function()
	{
		var objBind = VEvent.addListener(obj.map, "click", function(overlay, pt)
		{	
			if(_global.myMap.locCreating)
			{
				obj.HideIcon(_global.myMap.locCreating);
			}
			if(typeof(pt)!='undefined')
			{				
				var rec=obj.CreateRec(pt.latitude,pt.longitude,1);
                                
                var strHTML = '<div class = "info" style="width:280px; height:270px;z-index:0; margin-top:0px;" >'+new_loc+
                                '<from id ="VM"  style="margin-top:0px;" >'+
                                    '<table style="margin-top:0px;" border=0 cellpadding=1 cellspacing=1>'+
                                        '<tr>'+
                                            '<td width="100px" align="right">'+new_name+'</td>'+
                                            '<td width="150px"><input type="text" name="txtLocName" id="txtLocName" value="" maxlength="60" style="width: 150px;"></td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td align="right">'+new_address+'</td>'+
                                            '<td><input type="text" name="txtAddress" id="txtAddress" value="" maxlength="200" style="width: 150px;"></td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td align="right">'+new_loc_type+'</td>'+
                                            '<td>'+
                                            '<select name="ddlLocType" id="ddlLocType" style="width:152px;">'+
                                            '<option value="">'+new_loc_type_select+'</option>';
                                            for (var i=0; i<_arrLocationType.length; i++) {
                                                strHTML += '<option value="'+_arrLocationTypeId[i]+'">'+_arrLocationType[i]+'</option>';
                                            }
                                strHTML += '</select>'+
                                            '</td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td align="right">'+new_contact+'</td>'+
                                            '<td><input type="text" name="txtContact" id="txtContact" value="" maxlength="200" style="width: 150px;"></td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td align="right">'+new_phone+'</td>'+
                                            '<td><input type="text" name="txtPhone" id="txtPhone" value="" maxlength="20" style="width: 150px;"></td>'+
                                        '</tr>'+                                         
                                        '<tr>'+
                                            '<td align="right">'+new_amount+'</td>'+
                                            '<td><input type="text" size="2" name="txtFee" id="txtFee" value="" style="width: 150px;"></td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td align="right">'+new_radius+'</td>'+
                                            '<td><input type="text" size="2" name="txtRad" id="txtRad" value="1" style="width: 40px;"> '+units+' 100m</td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td align="right">'+description+'</td>'+
                                            '<td><textarea name="txtDesc" id="txtDesc" maxlength="225" style="width: 150px; height: 40px; overflow: auto;"></textarea></td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td></td>'+
                                            '<td align="left">'+
                                                '<input type="submit" onclick="_global.locs.SaveLoc()" value="'+btnsave+'" name="B1">'+
                                                '<input type="reset" value="'+btncancel+'" name="B2" onclick="_global.myMap.HideInfo();_global.myMap.DeleteLocation(_global.myMap.locCreating);">'+
                                            '</td>'+
                                        '</tr>'+
                                    '</table>'+
                                '<input type="hidden" name="clickLat"  id="clickLat"  value='+pt.lat()+'>'+
                                '<input type="hidden" name="clickLng"  id="clickLng"  value='+pt.lng()+'>'+
                                '</from>'+
                              '</div>';
                              
				obj.locCreating=obj.DrawLocationRec(rec.lat1,rec.lng1,rec.lat2,rec.lng2);
				obj.map.openInfoWindow(pt,strHTML);
			}
		}		
		);
		return(objBind);
	}
	obj.CreateRec = function(lat,lng,rad)
	{
		if(_global.myMap.locCreating)
			_global.myMap.DeleteLocation(_global.myMap.locCreating);
		var latclick = parseFloat(lat);
		var lngclick = parseFloat(lng);

		var result=new Object();
		var radius = 4*rad*1.609344;
		
		var latConv = 7347.086392356055;
		var	lngConv = 7215.3469046674845;
		var point1 = new VLatLng(latclick + (radius/latConv * Math.cos(0* Math.PI/180)), lngclick + (radius/lngConv * Math.sin(0 *Math.PI/180)));								
		var point2 = new VLatLng(latclick + (radius/latConv * Math.cos(90* Math.PI/180)), lngclick + (radius/lngConv * Math.sin(90 *Math.PI/180)));
		var point3 = new VLatLng(latclick + (radius/latConv * Math.cos(180* Math.PI/180)), lngclick + (radius/lngConv * Math.sin(180 *Math.PI/180)));								
		var point4 = new VLatLng(latclick + (radius/latConv * Math.cos(270* Math.PI/180)), lngclick + (radius/lngConv * Math.sin(270 *Math.PI/180)));	
		result.lat1=point1.latitude;
		result.lng1=point4.longitude;
		result.lat2=point3.latitude;
		result.lng2=point2.longitude;
		return result;
	}
	obj.Contains = function(polygon,point)
	{
        var j=0;
        var oddNodes = false;
        var x = point.longitude;
        var y = point.latitude;
		if(typeof(polygon)!='undefined')
		{
			for (var i=0; i < polygon.getVertexCount(); i++) 
			{
			  j++;
			  if (j == polygon.getVertexCount()) {j = 0;}
			  if (((polygon.getVertex(i).latitude < y) && (polygon.getVertex(j).latitude >= y))
			  || ((polygon.getVertex(j).latitude < y) && (polygon.getVertex(i).latitude >= y))) {
				if ( polygon.getVertex(i).longitude + (y - polygon.getVertex(i).latitude)
				/  (polygon.getVertex(j).latitude-polygon.getVertex(i).latitude)
				*  (polygon.getVertex(j).longitude - polygon.getVertex(i).longitude)<x ) {
				  oddNodes = !oddNodes
				}
			  }
			}
		}	
        return oddNodes;
    }
	obj.Makeinfo = function(index)
	{	
		var info = index.name;
			info=ToName(info);
		var latlng = new VLatLng(index.lat1,index.lng1); 
		var icn = new VIcon();
				icn.image = 'images/spacer.gif';
				icn.iconSize = new VSize(22, 22);			
				var mopt = new VMarkerOptions(icn, [info,''], 
					[new VTextPosition(V_ANCHOR_BOTTOM_RIGHT, new VSize(-15, -15)), 
					 new VTextPosition(V_ANCHOR_TOP_CENTER,new VSize(0,0))], 
					[new VTextStyle(12,'', '#0022dd', 'verdana'), new VTextStyle(10,'bold','#ff3322', 'Arial')]);
				var marker = new VMarker(latlng, mopt);						
			obj.map.addOverlay(marker);
		return marker;			
	}
	obj.CreateIconMap = function(newObj)  		// tao icon tren ban do
	{
		var name   	  = newObj.name;
		var lats1	  = newObj.lat1;
		var lngs1     = newObj.lng1;
		var lats2	  = newObj.lat2;
		var lngs2     = newObj.lng2;		
		var links     = newObj.link;
		
		var lat = (lats1 + lats2)/2;
		var lng = (lngs1 + lngs2)/2;
		//tilte = name;
		
		var pnt = new VLatLng(lat, lng);			
		var icn = new VIcon();
			icn.image = links;
			icn.iconSize = new VSize(22, 22);			
			var mopt = new VMarkerOptions(icn, [name], 
				[new VTextPosition(V_ANCHOR_BOTTOM_CENTER, new VSize(0, 0)), 
				new VTextPosition(V_ANCHOR_TOP_CENTER,new VSize(0,0))], 
				[new VTextStyle(10,'bold', '#0022dd', 'verdana'), new VTextStyle(10,'bold','#ff3322', 'Arial')]);
			var marker = new VMarker(pnt, mopt);						
			obj.map.addOverlay(marker);
			

			return marker;
	}
	function ToName(name)
	{
		try
		{	
			var arr1 = new Array();
			var str='';
			arr1 = name.split(" ");
			for(i=0;i<arr1.length-1;i++)
				str+=arr1[i]+"_";
			str+=arr1[arr1.length-1];
			return str;
		}
		catch(e)
		{
			return name;
		}
	}
	obj.DrawPolyline=function(latnew,longnew,latold,longold)
	{
		 var polyline = new VPolyline([
			new VLatLng(latnew,longnew),
			new VLatLng(latold,longold)
			], 'red', 2, 'red', 0.3);
		obj.map.addOverlay(polyline);
		return polyline;
	}
	
return obj;
}

